package pers.cz.mock;

import pers.cz.context.MyThreadLocals;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 接口回放时，获取请求中的特殊标识，如果存在特殊标识，则去数据库配置请求响应，不做真正的查询。
 * @program: postgirl-collection-client
 * @description: HttpRequestUpdate
 * @author: Cheng Zhi
 * @create: 2022-03-02 19:46
 **/
public class HttpRequestUpdate {

    public static void begin(HttpServletRequest request, HttpServletResponse response) {

        String cz = request.getHeader("cz");
        System.out.println("----cz----test---获取到的特殊请求头" + cz);
        if (request.getHeader("cz") != null) {
            MyThreadLocals.methodContext.set(String.valueOf(request.hashCode()));
        }
    }

    public static void end(HttpServletRequest request, HttpServletResponse response) {

        if (request.getHeader("cz") != null) {
            System.out.println("-------cz------test----销毁标识" +  MyThreadLocals.methodContext.get());
            MyThreadLocals.methodContext.remove();
        }
    }
}
